{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Install the SDK\n",
    "Refer to the **Installation** part of [README](https://github.com/microsoft/pai/blob/sdk-release-v0.4.00/contrib/python-sdk/README.md)\n",
    "\n",
    "*Note: now the code in a feature developping branch, will merge to master if stable*\n",
    "\n",
    "*Note 2: Restarting the kernel may be required to let python load the newly installed package*\n",
    "\n",
    "After installation, check it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import openpaisdk\n",
    "print(openpaisdk.__version__)\n",
    "print(openpaisdk.__container_sdk_branch__)\n",
    "print(openpaisdk.get_install_uri())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And also check the command line interface (CLI) tool `opai`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "! opai -h"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Sepcify `OpenPAI` cluster information\n",
    "Refer to corresponding part of [README](https://github.com/microsoft/pai/blob/sdk-release-v0.4.00/contrib/python-sdk/README.md)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Add a cluster\n",
    "User may add a new cluster by `opai cluster add` and attach a hdfs storage for it as below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "! opai cluster add --cluster-alias cluster-for-test --pai-uri http://x.x.x.x --user myuser --password mypassword\n",
    "! opai cluster attach-hdfs --default --cluster-alias cluster-for-test --storage-alias hdfs --web-hdfs-uri http://x.x.x.x:port"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## List your clusters\n",
    "User may list all specified clusters by `opai cluster list`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from openpaisdk.command_line import Engine\n",
    "\n",
    "cluster_cfg = Engine().process(['cluster', 'list'])[\"cluster-for-test\"]\n",
    "cluster_cfg"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}